/*
 * @Author: Crazy_Debug yangcheng960813@163.com
 * @Date: 2023-03-15 19:36:59
 * @LastEditTime: 2023-03-22 19:53:59
 * @LastEditors: Crazy_Debug yangcheng960813@163.com
 * @Description: 
 * @FilePath: /shaonao2/assets/Cocos-libs/screenAdapter/CanvasFit.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu("ScreenFit/CanvasFit")
export default class CanvasFit extends cc.Component {

    onLoad() {
        // cocos 场景适配
        const designResolution = cc.view.getDesignResolutionSize();
        const canvas = this.node.getComponent(cc.Canvas);
        if (cc.winSize.width / cc.winSize.height < designResolution.width / designResolution.height) {
            canvas.fitWidth = true;
            canvas.fitHeight = false;
        } else {
            canvas.fitWidth = false;
            canvas.fitHeight = true;
        }

        // 1. 先找到 SHOW_ALL 模式适配之后，本节点的实际宽高以及初始缩放值
        // let scaleForShowAll = Math.min(
        //     cc.view.getCanvasSize().width / this.node.width,
        //     cc.view.getCanvasSize().height / this.node.height
        // );
        // let realWidth = this.node.width * scaleForShowAll;
        // let realHeight = this.node.height * scaleForShowAll;

        // // 2. 基于第一步的数据，再做缩放适配
        // this.node.scale = Math.max(
        //     cc.view.getCanvasSize().width / realWidth,
        //     cc.view.getCanvasSize().height / realHeight
        // );

        // // 2. 基于第一步的数据，再做节点宽高重置
        // this.node.width = this.node.width *
        //     (cc.view.getCanvasSize().width / realWidth);
        // this.node.height = this.node.height *
        //     (cc.view.getCanvasSize().height / realHeight);
    }

}
